main: Support passing bare directory names to commit
authorColin Walters <walters@verbum.org>
Wed, 28 Aug 2013 21:32:21 +0000 (17:32 -0400)
committerColin Walters <walters@verbum.org>
Wed, 28 Aug 2013 21:32:21 +0000 (17:32 -0400)
It segfaulted before if you passed non-options, and a single directory
name is probably what people want.

src/ostree/ot-builtin-commit.c
tests/test-basic.sh

index 7558ef473e1d301b21a952bce959020e780bb086..a62aa8bf04dbeb8f35da173a8cf23bdc0c270c3d 100644 (file)
@@ -212,7 +212,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
 
   mtree = ostree_mutable_tree_new ();
 
-  if (argc == 1 && (opt_trees == NULL || opt_trees[0] == NULL))
+  if (argc <= 1 && (opt_trees == NULL || opt_trees[0] == NULL))
     {
       char *current_dir = g_get_current_dir ();
       arg = g_file_new_for_path (current_dir);
@@ -222,7 +222,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
                                                  cancellable, error))
         goto out;
     }
-  else
+  else if (opt_trees != NULL)
     {
       const char *const*tree_iter;
       const char *tree;
@@ -276,6 +276,14 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
             }
         }
     }
+  else
+    {
+      g_assert (argc > 1);
+      arg = g_file_new_for_path (argv[1]);
+      if (!ostree_repo_stage_directory_to_mtree (repo, arg, mtree, modifier,
+                                                 cancellable, error))
+        goto out;
+    }
 
   if (mode_adds && g_hash_table_size (mode_adds) > 0)
     {
index de372bdbcc36432b05d4276cbb48a881ef2a4886..0c17fc5bf6013a5ac8e97cd4dd1375296655930a 100755 (executable)
@@ -19,7 +19,7 @@
 
 set -e
 
-echo "1..39"
+echo "1..40"
 
 . $(dirname $0)/libtest.sh
 
@@ -275,3 +275,10 @@ $OSTREE reset test6 $checksum1
 $OSTREE show test6 > show-output
 assert_file_has_content show-output "commit $checksum1"
 echo "ok basic reset"
+
+cd ${test_tmpdir}
+rm checkout-test2 -rf
+$OSTREE checkout test2 checkout-test2
+touch checkout-test2/sometestfile
+$OSTREE commit -s sometest -b test2 checkout-test2
+echo "ok commit with directory filename"